//
//  XDOrganizationHeaderView.m
//  XDEducation
//
//  Created by apple on 2017/4/25.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDOrganizationHeaderView.h"

@interface XDOrganizationHeaderView ()

/** 查找 */
@property(nonatomic,strong) UIButton *searchBtn;

/** 标题数组 */
@property(nonatomic,strong) NSArray *titleArr;




@end

@implementation XDOrganizationHeaderView

-(instancetype)init{
    
    if (self = [super init]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        CGFloat padding = 15;
        
        //查找按钮
        CGFloat searchBtnW = 50;
        
        _searchBtn = [[UIButton alloc]init];
        _searchBtn.frame = CGRectMake(ScreenW - padding - searchBtnW, 20, searchBtnW, 30);
        [_searchBtn setBackgroundImage:[UIImage imageNamed:@"experience_btn_gray_default"] forState:UIControlStateNormal];
        [_searchBtn setTitle:@"查找" forState:UIControlStateNormal];
        [_searchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_searchBtn addTarget:self action:@selector(searchBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_searchBtn];
        
        CGFloat btnPadding = 10;
        CGFloat btnW = ((ScreenW - 30) - btnPadding * 2 - searchBtnW - 10)/3;
        CGFloat btnH = 30;
        CGFloat btnX = 15;
        for (int i = 0; i < 3; i ++) {
           
            UIButton *button = [[UIButton alloc]init];
            button.frame = CGRectMake(btnX + (btnW + btnPadding) * i, 20, btnW, btnH);
            [button setBackgroundImage:[UIImage imageNamed:@"experience_btn_default"] forState:UIControlStateNormal];
            button.tag = i;
            
            [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
            
            UILabel *label = [[UILabel alloc]init];
            label.frame = CGRectMake(0, 0, btnW - 28, btnH);
            
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = UIColorFromRGB(0x808080);
            label.font = [UIFont systemFontOfSize:14];
            label.text = self.titleArr[i];
            if (i == 0) {
                self.provinceLabel = label;
            }else if(i == 1){
                self.cityLabel = label;
            }else{
                self.areaLabel = label;
            }
            
            [button addSubview:label];
            
            [self addSubview:button];
            
        }
        
    }
    return self;
}

-(NSArray *)titleArr{
    if (_titleArr == nil) {
        _titleArr = [NSArray arrayWithObjects:
                     @"省份",
                     @"市",
                     @"县",
                     nil];
    }
    return _titleArr;
}

-(void)buttonClicked:(UIButton *)button{
    
    if (self.headerViewBlock) {
        self.headerViewBlock();
    }
}

-(void)searchBtnClicked{
    if (self.searchBlock) {
        self.searchBlock();
    }
}

@end
